<?php

namespace app\common\model;

class User extends BaseModel
{
    public function add($data = [])
    {
        $data['status'] = 1;
        $data['code'] = mt_rand(100000, 999999);
        $data['password'] = MD5($data['password'] . $data['code']);
        return $this->allowField(true)->save($data);
    }

    public function getUserByUsername($username)
    {
        if (!$username) {
            exception('用户名不合法');
        }
        $res = $this->where(['username' => $username])->find();
        return $res;
    }
}
